package com.elves.cloud.controller;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.datetime.standard.DateTimeFormatterFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Getter
@Slf4j
@Controller
// @RequestMapping("/server")
public class AppAction {

    static LocalDateTime time = LocalDateTime.now();

    public static void setTime(LocalDateTime timeNew) {
        time = timeNew;
    }

//    @GetMapping("/login")
//    public ModelAndView login() {
//        log.info("这是elves client login啊");
//        RedirectView redirectView = new RedirectView("http://127.0.0.1:9000/login");
//        redirectView.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
//        ModelAndView view = new ModelAndView();
//        view.setView(redirectView);
//        return view;
//    }

    // 不需要认证，不需要角色
    @GetMapping(value = "/time")
    @ResponseBody
    public ResponseEntity<Object> time() {
        return new ResponseEntity<>("Welcome to elves time ! 當前时间：" + LocalDateTime.now().format(new DateTimeFormatterFactory().createDateTimeFormatter()), HttpStatus.OK);
    }


    @GetMapping(value = "/user/{id}")
    @ResponseBody
    public ResponseEntity<Object> userGetID(@PathVariable String id) {
        return new ResponseEntity<>("elves user Welcome 【" + id + "】 at " + LocalDateTime.now().format(new DateTimeFormatterFactory().createDateTimeFormatter()), HttpStatus.OK);
    }

    @GetMapping(value = "/admin/{id}")
    @ResponseBody
    public ResponseEntity<Object> adminGetID(@PathVariable String id) {
        return new ResponseEntity<>("elves admin Welcome 【" + id + "】 at " + LocalDateTime.now().format(new DateTimeFormatterFactory().createDateTimeFormatter()), HttpStatus.OK);
    }


    // 需要认证，需要角色
    @GetMapping(value = "/userinfo")
    @ResponseBody
    public ResponseEntity<Object> userinfo() {
        return new ResponseEntity<>("userinfo to elves app! 系统启动时间：" + LocalDateTime.now().format(new DateTimeFormatterFactory().createDateTimeFormatter()), HttpStatus.OK);

    }



}
